<script setup lang="ts">
import { toRefs, reactive, onMounted, watch } from 'vue';
import SearchVue from '@/components/icon/Search.vue';
const props = defineProps({
  list: {
    type: Array,
    default: [] as Array<Record<string, any>>
  },
})
const { list } = toRefs(props)
const state = reactive({
  list: [] as any,
})
onMounted(() => {
  state.list = list.value
})
watch(list, (val: any) => {
  state.list = val
})
</script>

<template>
  <div class="container">
    <div class="brand-list flex flex-wrap">
      <router-link class="brand-item" v-for="item in state.list" :key="item.id" :to="item.url">
        <div class="img-wrap">
          <div class="img">
            <img :src="item.cover_url" :alt="item.title">
          </div>
          <div class="icon">
            <SearchVue color="#fff"></SearchVue>
          </div>
        </div>
        <div class="title text-center line-1">{{ item.title }}</div>
      </router-link>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.brand-list {
  padding-top: 60px;
}

.brand-item {
  position: relative;
  width: 350px;
  cursor: pointer;

  &:not(:nth-child(4n)) {
    margin-right: 13px;
  }

  .img-wrap {
    overflow: hidden;
    position: relative;
    width: 350px;
    padding-top: 300px;
    border-radius: 12px;

    &::after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      z-index: 10;
      display: block;
      background-color: rgba(0, 0, 0, 0);
      width: 100%;
      height: 100%;
      transition: all 0.6s ease 0s;
    }

    .img {
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 300px;
      margin: auto;
      transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    .icon {
      position: absolute;
      top: -30%;
      left: 50%;
      width: 40px;
      height: 40px;
      background-color: rgba(0, 0, 0, 0.3);
      transition: all .6s ease;
      transform: translate(-50%, -50%);
    }
  }

  .title {
    padding: 40px 0;
    color: #222;
    font-size: 14px;
  }

  &:hover {
    .img-wrap {
      &::after {
        background-color: rgba(0, 0, 0, 0.08);
      }

      .img {
        transform: scale(1.2, 1.2);
      }

      .icon {
        top: 50%;
      }
    }
  }
}
</style>
